package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;
import java.util.Arrays;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.TaskUserTrajectory;
import com.ruoyi.business.service.ITaskUserTrajectoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调研人员轨迹Controller
 *
 * @author Eric
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/business/trajectory")
public class TaskUserTrajectoryController extends BaseController {
    @Resource
    private ITaskUserTrajectoryService taskUserTrajectoryService;

    /**
     * 查询调研人员轨迹列表
     */
    @PreAuthorize("@ss.hasPermi('business:trajectory:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskUserTrajectory taskUserTrajectory) {
        startPage();
        List<TaskUserTrajectory> list = taskUserTrajectoryService.list(Wrappers.lambdaQuery(TaskUserTrajectory. class).
        setEntity( taskUserTrajectory));
        return getDataTable(list);
    }

    /**
     * 导出调研人员轨迹列表
     */
    @PreAuthorize("@ss.hasPermi('business:trajectory:export')")
    @Log(title = "调研人员轨迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskUserTrajectory taskUserTrajectory) {
        List<TaskUserTrajectory> list = taskUserTrajectoryService.list(Wrappers.lambdaQuery(TaskUserTrajectory. class).
        setEntity( taskUserTrajectory));
        ExcelUtil<TaskUserTrajectory> util = new ExcelUtil<TaskUserTrajectory>(TaskUserTrajectory. class);
        util.exportExcel(response, list, "调研人员轨迹数据");
    }

    /**
     * 获取调研人员轨迹详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:trajectory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(taskUserTrajectoryService.getById(id));
    }

    /**
     * 新增调研人员轨迹
     */
    @PreAuthorize("@ss.hasPermi('business:trajectory:add')")
    @Log(title = "调研人员轨迹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskUserTrajectory taskUserTrajectory) {
        return toAjax(taskUserTrajectoryService.save(taskUserTrajectory));
    }

    /**
     * 修改调研人员轨迹
     */
    @PreAuthorize("@ss.hasPermi('business:trajectory:edit')")
    @Log(title = "调研人员轨迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskUserTrajectory taskUserTrajectory) {
        return toAjax(taskUserTrajectoryService.updateById(taskUserTrajectory));
    }

    /**
     * 删除调研人员轨迹
     */
    @PreAuthorize("@ss.hasPermi('business:trajectory:remove')")
    @Log(title = "调研人员轨迹", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(taskUserTrajectoryService.removeBatchByIds(Arrays.asList(ids)));
    }
}
